﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>bom查询</title>
    <link href="~/Scripts/jquery-easyui/themes/bootstrap/easyui.css" rel="stylesheet" />
    <script src="~/Scripts/jquery-easyui/jquery.min.js"></script>
    <script src="~/Scripts/jquery-easyui/jquery.easyui.min.js"></script>
    <script src="~/Scripts/jquery-easyui/locale/easyui-lang-zh_CN.js"></script>
    <link href="~/Content/themes/icon.css" rel="stylesheet" />
    <script src="~/Content/js/common.js"></script>
    <link href="~/Content/themes/table.css" rel="stylesheet" />
    <script type="text/javascript">
        var _FItemID;
        //表格列定义
        var myColums = [[
                       { width: 80, title: 'Bom编码', field: 'bomID', sortable: true, hidden: true },
                         { width: 80, title: '物料编码', field: 'FItemID', hidden: true },
                          { width: 80, title: '物料代码', field: 'FNumber', hidden: false },

                            { width: 150, title: '物料名称', field: 'FName', hidden: false },
                           { width: 150, title: '规格型号', field: 'FModel', hidden: false },
                              { width: 100, title: '材料价格', field: 'itemPrice', hidden: false },
                                 { width: 100, title: '工时', field: 'worktime', hidden: false },
                                    { width: 100, title: '净重', field: 'FGrossWeight', hidden: false },
                            { width: 100, title: '订单价格', field: 'FOrderPrice', hidden: true },
                              {
                                  width: 100, title: '操作', field: '_operate', formatter:

                                     function (val, row, index) {
                                         return '<a href="javascript:void(0)" onclick="showBom(' + row.FItemID + ')">查看</a>';
                                     }
                              },

        ]];
        var KeyName = "bomItem";
        var eID = "#ui_bom_dg";
        var url = "/Bom/GetBomItem";

        $(function () {
            $.ajax({     //请求当前用户可以操作的按钮
                url: "/Button/GetUserAuthorizeButton?r=" + Math.random(),
                type: "post",
                data: { "KeyCode": "bomItem", "KeyName": "bomItem" },
                dataType: "json",
                timeout: 5000,
                success: function (data) {
                    if (data.success) {
                        var toolbar = getToolBar(data);      //common.js
                        if (data.search) {     //判断是否有浏览权限
                            $("#ui_bom_dg").datagrid({       //初始化datagrid
                                url: url,
                                striped: true, rownumbers: true, pagination: true, pageSize: 20, singleSelect: true, multiSort: false,
                                //idField: 'id',
                                //sortName: 'UpdateTime',
                                //sortOrder: 'desc',
                                pageList: [20, 40, 60, 80, 100],
                                // frozenColumns:  ,
                                columns: myColums,
                                onDblClickRow: function (index, row) {
                                    showBom(row.FItemID);
                                },

                                toolbar: toolbar.length == 0 ? null : toolbar
                            });
                        }
                        else {
                            $.show_alert("提示", "无权限，请联系管理员！");
                        }
                    } else {
                        $.show_alert("错误", data.result);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    if (textStatus == "timeout") {
                        $.show_alert("提示", "请求超时，请刷新当前页重试！");
                    }
                    else {
                        $.show_alert("错误", textStatus + "：" + errorThrown);
                    }
                }
            })

        });

        //搜索任务单
        function ui_bom_searchdata() {
            $("#ui_bom_dg").datagrid('load', {
                // FBillNo: $('#FBillNo').val(),
                FName: $('#FName').val(),
                FModel: $('#FModel').val(),
                fbominterid: $('#fbominterid').val()
            });
            $("#ui_bom_dg").datagrid('clearSelections').datagrid('clearChecked');
        }
        //清除搜索条件
        function ui_bom_cleardata() {
            $('#ui_project_search input').val('');
            $("#ui_user_dg").datagrid('load', {});
            $("#ui_user_dg").datagrid('clearSelections').datagrid('clearChecked');
        }
        //显示bom表
        function showBom(FItemID) {
            _FItemID = FItemID;
            $('#bomtree').treegrid('loadData', { total: 0, rows: [] });
            $('#bomtree').treegrid('reload', { itemid: FItemID });
            $('#win').window('open');
            $('#win').window("resize", { top: $(document).scrollTop() + ($(window).height() - 450) * 0.5 });//居中显示
        }
        function exportsave() {

            //$.show_alert("提示", "接口功能正在开发中！");
            //return;

            var url = "/Bom/ExportExcel?r=" + Math.random();
            var data = {
                "FItemID": _FItemID,
                "filetype": "excel",
            };
            download(url, data, 'post');

        }


    </script>
</head>
<body>
    <div id="ui_bom_layout" class="easyui-layout" data-options="fit:true,border:false" style=" height:220px;">
        <div data-options="region:'north',split:true,border:true,collapsed:false" title="条件搜索" style="height:80px;">
            <div id="ui_bom_search">
                <table class="tableForm" style="width: 99%; height: 100%; background: #F5F5F5;">
                    <tr>
                        @*<th>
                                订单号：
                            </th>
                            <td>
                                <input name="FBillNo" id="FBillNo" class="easyui-validatebox textbox" style="width:150px;height:22px;" />
                            </td>*@

                        <th>
                            物料名称：
                        </th>
                        <td>
                            <input name="FName" id="FName" class="easyui-validatebox textbox" style="width:150px;height:22px;" />
                        </td>

                        <th>
                            规格型号：
                        </th>
                        <td>
                            <input name="FModel" id="FModel" class="easyui-validatebox textbox" style="width:150px;height:22px;" />
                        </td>
                        <th>
                            Bom ID：
                        </th>
                        <td>
                            <input id="fbominterid" name="fbominterid" class="easyui-validatebox textbox" style="width:150px;height:22px;" />
                        </td>

                        <td colspan="4">
                            <a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-search" plain="true"
                               onclick="ui_bom_searchdata();">搜索</a>
                            <a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-clear" plain="true"
                               onclick="ui_bom_cleardata();">清空条件</a>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div data-options="region:'center',border:false">
            <table id="ui_bom_dg" data-options="fit:true,border:false"></table>
        </div>
    </div>
    <div id="win" class="easyui-window" title="Bom表" style="width:900px;height:550px"
         data-options="closed:true,iconCls:'icon-save',modal:true">
        <a id="btn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="javascript: $('#bomtree').treegrid('expandAll');">全部展开</a>
        <a id="btn" href="#" class="easyui-linkbutton" data-options="iconCls: 'icon-remove'" onclick="javascript: $('#bomtree').treegrid('collapseAll');">全部收起</a>
        <a id="btn" href="#" class="easyui-linkbutton" data-options="iconCls: 'icon-save'" onclick="javascript: exportsave();">导出</a>

        <table id="bomtree" style="width:780px;height:540px" class="easyui-treegrid"
               data-options="
               url:'/Bom/getBomData',
                method: 'get',
                state:'closed',
                rownumbers: true,
                idField: 'FNumber',
                treeField: 'FNumber'
            ">
            <thead>
                <tr>
                    @*<th data-options="field:'FItemID'" width="160">物料ID</th>
                        <th data-options="field:'FinterID'" width="80" align="right">Bom ID</th>*@

                    <th data-options="field:'FNumber'" width="150">物料代码</th>
                    <th data-options="field:'FName'" width="150">名称</th>
                    <th data-options="field:'FModel'" width="150">规格型号</th>
                    <th data-options="field:'FQty'" width="80">数量</th>
                    <th data-options="field:'itemPrice'" width="80">材料价格</th>
                    <th data-options="field:'worktime'" width="80">工时</th>
                    <th data-options="field:'FGrossWeight'" width="80">净重</th>
                </tr>
            </thead>
        </table>

    </div>
</body>
</html>
